<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <title>Example</title>
    <link rel="stylesheet" href="./css/common.css">
    <link rel="stylesheet" href="./css/type.css">
    <link rel="stylesheet" href="./plugins/swiper/swiper-bundle.min.css">
    <script src="./js/vue.min.js"></script>
    <link rel="shortcut icon" href="./favicon.png" type="image/x-icon">
</head>

<body>
    <div id="app">
        <m-Header></m-Header>

        <div class="ad">
            <div class="ad-wrapper"></div>
            <span>Advertisement</span>
        </div>
        <main>
            <div class="wrapper">
                <div class="games">
                    <div class="games-title">
                        <img :src="imgUrl" :alt="name" width="20">
                        <span>{{name}} Games</span>
                    </div>
                    <div class="games-content">
                        <a :href="handleTypeToDetail(game.gameId)" class="games-wrapper" v-for="game in list">
                            <div class="games-wrapper-logo">
                                <img class="games-wrapper-logo_icon" :src="game.gameLogo" :alt="game.gameName">
                            </div>
                            <span class="games-wrapper-name">{{game.gameName}}</span>
                        </a>
                    </div>
                </div>
            </div>
            <m-Hot></m-Hot>
        </main>

        <m-Footer></m-Footer>
    </div>
</body>
<script src="./main.js"></script>
<script src="./plugins/swiper/swiper-bundle.min.js"></script>
<script type="module">
    import { Header, Footer } from './components/index.js'
    import Hot from './components/hot.js'
    var vm = new Vue({
        el: '#app',
        components: {
            mHeader: Header,
            mFooter: Footer,
            mHot: Hot
        },
        data() {
            return {
                id: 12,
                name: '',
                list: []
            }
        },
        computed: {
            imgUrl() {
                return `./imgs/${this.name.toLowerCase()}.webp`
            }
        },
        created() {
            this.id = getQueryVariable('id') || 12
            this.name = getQueryVariable('name') || 'Strategy'
            document.title = `${this.name} Games`
            this.getGameList()
        },
        mounted() {
        },
        methods: {
            handleTypeToDetail(id) {
                return `./detail.html?id=${id}&name=${this.name}&typeId=${this.id}`
            },
            getGameList() {
                fetch('https://www.migame.vip/gamefront/gameList/SelectGameByGameType', {
                    headers: {
                        'Content-Type': 'application/json; charset=utf-8'
                    },
                    method: 'post',
                    body: JSON.stringify({
                        gameTypeId: this.id,
                        limit: 40,
                        page: 1,
                    })
                })
                    .then(res => res.json())
                    .then(res => {
                        this.list = res.data
                    })
                    .catch(function (error) {
                        // 请求失败后执行的回调函数
                        console.log('error:', error)
                    })
            },
        }
    })
</script>

</html>